// 引入一级路由组件
// import Home from '../pages/Home'
import Search from '../pages/Search'
import Login from '../pages/Login'
import Register from '../pages/Register'
import Detail from '../pages/Detail'
import AddCartSuccess from '../pages/AddCartSuccess'
import ShopCart from '../pages/ShopCart'
import Trade from '../pages/Trade'
import Pay from '../pages/Pay'
import PaySuccess from '../pages/PaySuccess'
import Center from '../pages/Center'


// 引入二级路由组件
import Myorder from '../pages/Center/MyOrder'
import GroupOrder from '../pages/Center/GroupOrder'

// 配置路由信息
export default [
  {
    path: '/home',
    // 直接在这里面直接引入
    component: () => import('../pages/Home'),
    meta: { show: true },
  },
  {
    path: '/search/:keyword?',
    component: Search,
    meta: { show: true },
    name: 'search',
    //路由也可以传递props数据，拥有三种写法
    //如果 props 被设置为 true，params参数将会被设置为组件属性
    // props:true,
    // props:{a:1,b:2}
    props: (route) => ({ keyWord: route.params.keyWord, k: route.query.k }),
  },
  {
    path: '/login',
    component: Login,
    meta: { show: false },
  },
  {
    path: '/register',
    component: Register,
    meta: { show: false },
  },
  {
    path: '/detail/:skuId?',
    component: Detail,
    meta: { show: true },
  },
  {
    path: '/addcartsuccess',
    name: 'addcartsuccess',
    component: AddCartSuccess,
    meta: { show: true },
  },
  {
    path: '/shopcart',
    component: ShopCart,
    meta: { show: true },
  },
  {
    path: '/trade',
    component: Trade,
    meta: { show: true },
    // 路由独享守卫
    beforeEnter: (to, from, next) => {
      if (from.path == '/shopcart') {
        next()
      } else {
        next(false)
      }
    },
  },
  {
    path: '/pay',
    component: Pay,
    meta: { show: true },
    // 路由独享守卫
    beforeEnter: (to, from, next) => {
      if (from.path == '/trade') {
        next()
      } else {
        next(false)
      }
    },
  },
  {
    path: '/paysuccess',
    component: PaySuccess,
    meta: { show: true },
  },
  {
    path: '/center',
    component: Center,
    meta: { show: true },
    children: [
      {
        path: 'myorder',
        component: Myorder,
      },
      {
        path: 'grouporder',
        component: GroupOrder,
      },
      {
        path: '',
        redirect: 'myorder',
      },
    ],
  },
  {
    path: '/',
    redirect: '/home',
  },
]
